package io.gitee.wminyu.day02;

import java.util.Arrays;

public class sum_of_Array {
    public static void main(String[] args){
        double [][] matrix = {
                {1.5, 2, 3, 4},
                {2.3, 5, 8, 9},
                {3, 5.4, 7, 10}
        };
//        for ( int i=0; i<matrix.length; i++){
//            System.out.print(Arrays.toString(matrix[i]));
//        }
        sumColumn(matrix,0);
        sumColumn(matrix, 1);
        sumColumn(matrix, 2);
//        sumColumn(matrix, 3);
        System.out.println(Arrays.toString(sumColumns(matrix)));
    }
    public static double sumColumn(double[][] matrix, int column){
        double sum=0;
        for (int i=0; i<matrix.length; i++){
            sum+=matrix[i][column];
//            System.out.println(sum);
        }
        System.out.println(sum);
        return sum;
    }
    public static double[] sumColumns(double[][] matrix){
        double []s = new double[matrix.length+1];
        for (int i=0;i<matrix.length+1;i++){
            s[i] = sumColumn(matrix,i);
        }
        return s;
    }
}
